package com.yuliang.utils.result;



import com.alibaba.fastjson.JSONObject;
import com.yuliang.utils.result.emums.HttpCodeEnum;

import java.util.HashMap;
import java.util.Map;

/**
 * @author admin
 */
public class ResultUtils {
    public final static String CODE = "code";
    public final static String DATA = "data";
    public final static String MESSAGE = "message";
    public final static int NUM_TWO = 2;
    public final static int NUM_THREE = 3;
    /**
     * 返回结果【只携带消息】
     * */
    public static String resultWithMessage(Object code, String message){
        Map<Object, Object> map = new HashMap<>(NUM_TWO);
        map.put(CODE, code);
        map.put(MESSAGE, message);
        return JSONObject.toJSONString(map);
    }
    /**
     * 枚举类自定义状态码返回
     * */
    public static String ResultWithMessageEnum(HttpCodeEnum httpCodeEnum){
        Object code = httpCodeEnum.getCode();
        String message = httpCodeEnum.getMessage();
        Map<Object, Object> map = new HashMap<>(NUM_TWO);
        map.put(CODE, code);
        map.put(MESSAGE, message);
        return JSONObject.toJSONString(map);
    }
    /**
     * 枚举类带数据的状态码返回
     * */
    public static String ResultWithMessageDataEnum(HttpCodeEnum httpCodeEnum, Object data){
        Object code = httpCodeEnum.getCode();
        String message = httpCodeEnum.getMessage();
        Map<Object, Object> map = new HashMap<>(NUM_THREE);
        map.put(CODE, code);
        map.put(DATA, data);
        map.put(MESSAGE, message);
        return JSONObject.toJSONString(map);
    }

    /**
     * 枚举类带数据不带消息返回
     * */
    public static String ResultWithDataEnum(HttpCodeEnum httpCodeEnum, Object data){
        Object code = httpCodeEnum.getCode();
        Map<Object, Object> map = new HashMap<>(NUM_TWO);
        map.put(CODE, code);
        map.put(DATA, data);
        return JSONObject.toJSONString(map);
    }
}
